import Vue from 'vue'
import * as apis from '../../services/apis'
import * as types from '../mutation-types'
import services from '../../services'
import http from '../../http'
const state = {
  categorys: [],
  categoryProList: []
}

const getters = {
  categorys: state => state.categorys,
  categoryProList: state => state.categoryProList
}

const actions = {
  // 获取类别
  getCategorys({
    commit
  }, payload) {
    Vue.http.post(apis.GET_CATEGORY).then((res) => {
      commit(types.GET_CATEGORY, res.body)
    })
  },
  // 获取类别商品列表
  getProList({
    commit
  }, payload) {
    let url = apis.GET_CATEGORY_PRO + '/' + payload.categoryId
    Vue.http.post(url).then((res) => {
      commit(types.GET_CATEGORY_PRO, res.body)
    })
  }
}

const mutations = {
  [types.GET_CATEGORY](state, payload) {
    console.log(payload.result);
    state.categorys = payload.result
  },
  [types.GET_CATEGORY_PRO](state, payload) {
    console.log(payload.result);
    state.categoryProList = payload.result
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
